package com.company.cloud.uba.modules.bus.consumer;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.company.cloud.common.mq.redis.client.consumer.ISaasMqConsumer;
import com.company.cloud.common.mq.redis.client.consumer.MQConsumeMessage;
import com.company.cloud.common.mq.redis.client.consumer.MQSaasResult;
import com.company.cloud.common.mq.redis.client.consumer.annotation.MQRedisConsumer;
import com.company.cloud.uba.modules.app.service.UserLoginLogAppService;
import com.company.common.server.config.mq.constant.MQTopicKeys;
import com.company.common.server.config.mq.models.MQUserLoginModel;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 用户登录消费者
 * */
@Log4j2
@MQRedisConsumer(topic = MQTopicKeys.MQ_UserLogin_Topic,group="UBA_User_Login")
@Service
public class UserLoginRedisConsumer implements ISaasMqConsumer {

    @Autowired
    private UserLoginLogAppService userLoginLogAppService;


    @Override
    public MQSaasResult consume(MQConsumeMessage data) throws Exception {
        try {
            MQUserLoginModel entity= data.getContent(MQUserLoginModel.class);
            if(entity!=null){
                userLoginLogAppService.addUserLoginLog(entity);
            }
            return MQSaasResult.getSuccess(data.getId());
        }catch (Exception e){
            log.debug("+++++用户登录消费者,执行业务错误:",e.getCause());
            return MQSaasResult.FAIL;
        }
    }







}
